package com.stylefeng.guns.modular.count.controller;

import com.stylefeng.guns.core.base.controller.BaseController;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.beans.factory.annotation.Autowired;
import com.stylefeng.guns.core.log.LogObjectHolder;
import org.springframework.web.bind.annotation.RequestParam;
import com.stylefeng.guns.modular.system.model.LogClickCount;
import com.stylefeng.guns.modular.count.service.ILogClickCountService;

/**
 * 浏览统计控制器
 *
 * @author fengshuonan
 * @Date 2018-09-03 11:49:36
 */
@Controller
@RequestMapping("/logClickCount")
public class LogClickCountController extends BaseController {

    private String PREFIX = "/count/logClickCount/";

    @Autowired
    private ILogClickCountService logClickCountService;

    /**
     * 跳转到浏览统计首页
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "logClickCount.html";
    }

    /**
     * 跳转到添加浏览统计
     */
    @RequestMapping("/logClickCount_add")
    public String logClickCountAdd() {
        return PREFIX + "logClickCount_add.html";
    }

    /**
     * 跳转到修改浏览统计
     */
    @RequestMapping("/logClickCount_update/{logClickCountId}")
    public String logClickCountUpdate(@PathVariable Integer logClickCountId, Model model) {
        LogClickCount logClickCount = logClickCountService.selectById(logClickCountId);
        model.addAttribute("item",logClickCount);
        LogObjectHolder.me().set(logClickCount);
        return PREFIX + "logClickCount_edit.html";
    }

    /**
     * 获取浏览统计列表
     */
    @RequestMapping(value = "/list")
    @ResponseBody
    public Object list(@RequestParam(required = false) String name,
                       @RequestParam(required = false) String beginTime,
                       @RequestParam(required = false) String endTime,
                       @RequestParam(required = false) String typeCode) {
        return logClickCountService.getData(name, typeCode, beginTime, endTime);
    }

    /**
     * 新增浏览统计
     */
    @RequestMapping(value = "/add")
    @ResponseBody
    public Object add(LogClickCount logClickCount) {
        logClickCountService.insert(logClickCount);
        return SUCCESS_TIP;
    }

    /**
     * 删除浏览统计
     */
    @RequestMapping(value = "/delete")
    @ResponseBody
    public Object delete(@RequestParam Integer logClickCountId) {
        logClickCountService.deleteById(logClickCountId);
        return SUCCESS_TIP;
    }

    /**
     * 修改浏览统计
     */
    @RequestMapping(value = "/update")
    @ResponseBody
    public Object update(LogClickCount logClickCount) {
        logClickCountService.updateById(logClickCount);
        return SUCCESS_TIP;
    }

    /**
     * 浏览统计详情
     */
    @RequestMapping(value = "/detail/{logClickCountId}")
    @ResponseBody
    public Object detail(@PathVariable("logClickCountId") Integer logClickCountId) {
        return logClickCountService.selectById(logClickCountId);
    }
}
